#include "PlayerCharacter.h"
#include "MagicObject.h"
#include <qpainter.h>
#include <memory>

// Constructor
PlayerCharacter::PlayerCharacter() : Character() 
	, mIsToad(false)
	, mCraftCounter(0)
	, mStrengthCounter(0)
	, mLifeCounter(0)
	, mGoldCoinsInPossession(0)
	,mFateTokensInPossession(0)
	, mAllignmentSide(Allignment::eGoodSide)
	, toadTurnsLeft(0)
{
	toad.load("Images\\toad2.gif");
}

// Constructor
PlayerCharacter::PlayerCharacter(string iCharacterName
	, string iCharacterDescription
	, unsigned int iCharacterStrengthValue
	, unsigned int iCharacterCraftValue)
	: Character(iCharacterName, iCharacterDescription, iCharacterStrengthValue, iCharacterCraftValue)
	, mIsToad(false)
	, mCraftCounter(0)
	, mStrengthCounter(0)
	, mLifeCounter(0)
	, mGoldCoinsInPossession(0)
	, mFateTokensInPossession(0)
	, mAllignmentSide(Allignment::eGoodSide)
	, toadTurnsLeft(0)

{
	toad.load("Images\\toad2.gif");
}

// Destructor
PlayerCharacter::~PlayerCharacter()
{
	for (int i = 0; i < mFollowers.size(); ++i)
		delete mFollowers.at(i);

	for (int i = 0; i < mMagicObjects.size(); ++i)
		delete mMagicObjects.at(i);
}

unsigned int PlayerCharacter::getTotalCharacterStrength(void) const
{
	if (mIsToad)
	{
		return 1; // A toad has a strength value of 1, assume it can't accumulate any strength or craft at all
	}
	else
	{
		// The total strength is the sum of the strength value, its counters, and the total strength of all the followers and objects
		unsigned int wTotalCharacterStrengthValue = 0;
		wTotalCharacterStrengthValue += getStrengthValue();
		wTotalCharacterStrengthValue += getStrengthCounter();
		
		for (vector<NonPlayerCharacter *>::size_type i = 0; i < mFollowers.size(); ++i)
			wTotalCharacterStrengthValue += mFollowers[i]->getExtraStrengthValue();

		for (vector<MagicObject *>::size_type i = 0; i < mMagicObjects.size(); ++i)
			wTotalCharacterStrengthValue += mMagicObjects[i]->getExtraStrengthValue();

		return wTotalCharacterStrengthValue;
	}
}

unsigned int PlayerCharacter::getTotalCharacterCraft(void) const
{
	if (mIsToad)
	{
		return 1; // A toad has a craft value of 1, assume it can't accumulate any strength or craft at all
	}
	else
	{
		// The total craft is the sum of the craft value, its counters, and the total craft of all the followers and objects
		unsigned int wTotalCharacterCraftValue = 0;
		wTotalCharacterCraftValue += getCraftValue();
		wTotalCharacterCraftValue += getCraftCounter();

		for (vector<NonPlayerCharacter *>::size_type i = 0; i < mFollowers.size(); ++i)
			wTotalCharacterCraftValue += mFollowers[i]->getExtraCraftValue();

		for (vector<MagicObject *>::size_type i = 0; i < mMagicObjects.size(); ++i)
			wTotalCharacterCraftValue += mMagicObjects[i]->getExtraCraftValue();

		return wTotalCharacterCraftValue;
	}
}	

const QImage * PlayerCharacter::getPicture(void) const
{
	if (isToad())
		return &toad;
	else
		return Character::getPicture();
}